/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jifConsultarComprobante.java
 *
 * Created on 18-ago-2010, 14:34:30
 */

package Comprobantes;

import administracion.delegate.GestionPedidosDelegate;
import administracion.helper.Listas;
import administracion.helper.Utiles_MensajesDialogo;
import administracion.helper.Utiles_PDF;
import administracion.helper.jPaginacion;
import com.jidesoft.hints.ListDataIntelliHints;
import Proveedores.jifAdministrarProveedor;
import Ordenes.jifConsultarOrden;
import administracion.helper.MiTablePrint;
import java.awt.Frame;
import java.awt.event.KeyEvent;
import java.io.ByteArrayInputStream;
import java.math.BigDecimal;
import java.util.List;
import java.util.Observable;
import java.util.Observer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import org.jdesktop.beansbinding.AutoBinding;
import org.jdesktop.beansbinding.BindingGroup;
import org.jdesktop.beansbinding.ELProperty;
import org.jdesktop.swingbinding.JTableBinding;
import org.jdesktop.swingbinding.SwingBindings;
import suministros.ejb30.TO.AnoTO;
import suministros.ejb30.TO.ComprobantePagoTO;
import suministros.ejb30.TO.MesTO;
import suministros.ejb30.TO.ParametrosConsultaTO;
import suministros.ejb30.TO.ProveedorTO;
import suministros.ejb30.TO.ZonaTO;

/**
 *
 * @author Luis_Angel
 */
public class jifConsultarComprobante extends javax.swing.JInternalFrame implements Observer{

    private ListDataIntelliHints intelliHintsProveedor;
    private JTableBinding jTableBinding;
    private List<ComprobantePagoTO> comprobantes_encontradas;

    private jPaginacion panelPaginacion;
    private ParametrosConsultaTO params;
    private boolean admin;

    /** Creates new form jifConsultarComprobante */
    public jifConsultarComprobante(boolean admin) {
        this.panelPaginacion = new jPaginacion(this,15);
        initComponents();
        try {
            cargaHintsIndependientes();
        } catch (Exception ex) {
            Logger.getLogger(jifAdministrarProveedor.class.getName()).log(Level.SEVERE, null, ex);
        }
         try {
            Listas.cargarAnosMeses();
        } catch (Exception e) {
            Utiles_MensajesDialogo.mensajeError("Error al cargar Años");
        }

        llenarComboZona();
        llenarComboAno();

        this.admin = admin;
    }

      private void cargaHintsIndependientes() throws Exception {
         this.intelliHintsProveedor = new ListDataIntelliHints(this.jtfRazon,Listas.getProveedores());
    }

     private void llenarComboZona() {
        List listaZonas = null;
        List listaZonas_cbo = this.cboBeanBindingZona1.getLista();
        listaZonas_cbo.clear();
        try
        {
          listaZonas = Listas.getZonas();
          this.cboBeanBindingZona1.setLista(listaZonas);
          this.bindingGroup.bind();
          this.jcboZona.updateUI();
          this.jcboZona.setSelectedIndex(-1);
        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener zonas\n" + ex.getMessage());
          ex.printStackTrace();

        }
   }

      private void llenarComboAno()
      {
        List listaAnos = null;
        List listaAnos_cbo = this.cboBeanBindingAno1.getLista();
        listaAnos_cbo.clear();
        try
        {
          listaAnos = Listas.getAnos();
          this.cboBeanBindingAno1.setLista(listaAnos);
          this.bindingGroup.bind();
          this.jcboAno.updateUI();
          this.jcboAno.setSelectedIndex(-1);
        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener años\n" + ex.getMessage());
          ex.printStackTrace();

        }
      }

  private void llenarComboMes() {
    List listaMeses = null;
    List listaMeses_cbo = this.cboBeanBindingMes1.getLista();
    listaMeses_cbo.clear();
    try {
      if (this.jcboAno.getSelectedItem() != null) {
        AnoTO an = (AnoTO)this.jcboAno.getSelectedItem();
        listaMeses = Listas.getMesesAno(an);
        this.cboBeanBindingMes1.setLista(listaMeses);
        this.bindingGroup.bind();
        this.jcboMes.updateUI();
        this.jcboMes.setSelectedIndex(0);
      }
    } catch (Exception ex) {
      Utiles_MensajesDialogo.mensajeAlerta("Error al obtener meses\n" + ex.getMessage());
      ex.printStackTrace();

    }
  }

  private void buscarRazonSocial()
      {
        ProveedorTO pro;
        if (this.jtfRuc.getText().trim().length() < 1) {
              try { pro = (ProveedorTO)this.intelliHintsProveedor.getSelectedHint();
              } catch (NullPointerException ex) {
                pro = null;
              }
            }
        else {
          pro = Listas.getProveedorcodigo(this.jtfRuc.getText().trim());
        }
        if (pro == null) {
          Utiles_MensajesDialogo.mensajeError("El proveedor no existe!");
          this.jtfRuc.setText("");
          pro = null;
        }
        else {

          this.jtfRazon.setText(pro.getRazon() + " - " + pro.getCodProveedor());
          this.jtfRuc.setText(pro.getCodProveedor());
          buscar();
        }

      }

   public void buscarComprobantes(){
        try{
            comprobantes_encontradas = GestionPedidosDelegate.getInstance().consultarComprobante(params,this.panelPaginacion.getPagActual(),this.panelPaginacion.getPagTamano());
            actualizaTablaComprobantes(comprobantes_encontradas);
             if(comprobantes_encontradas.isEmpty()){
                 this.jbDetalles.setEnabled(false);
                 if(admin){
                     this.jbModificar.setEnabled(false);
                     this.jbModificarDatos.setEnabled(false);
                 }
                 
            }
            else{
                this.jbDetalles.setEnabled(true);
                if(admin){
                     this.jbModificar.setEnabled(true);
                     this.jbModificarDatos.setEnabled(true);
                }
                
            }
           
        } catch (Exception ex) {
            Logger.getLogger(jifConsultarOrden.class.getName()).log(Level.SEVERE, null, ex);
        }

     }

    private void actualizaTablaComprobantes(List<ComprobantePagoTO> comprobantes_encontradas) {
            this.bindingGroup = new BindingGroup();
            this.jTableBinding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ,comprobantes_encontradas , this.jtComprobantes);

            JTableBinding.ColumnBinding columnBinding0 = this.jTableBinding.addColumnBinding(ELProperty.create("${nro_orden}"));

            columnBinding0.setColumnName("Nro Orden");
            columnBinding0.setColumnClass(String.class);
            columnBinding0.setEditable(false);

            JTableBinding.ColumnBinding columnBinding1= this.jTableBinding.addColumnBinding(ELProperty.create("${tipo_comprobante}"));

            columnBinding1.setColumnName("Comprobante");
            columnBinding1.setColumnClass(String.class);
            columnBinding1.setEditable(false);


            JTableBinding.ColumnBinding columnBinding2 = this.jTableBinding.addColumnBinding(ELProperty.create("${serie_comprobante}"));

            columnBinding2.setColumnName("Serie");
            columnBinding2.setColumnClass(String.class);
            columnBinding2.setEditable(false);

            JTableBinding.ColumnBinding columnBinding3 = this.jTableBinding.addColumnBinding(ELProperty.create("${numero_comprobante}"));

            columnBinding3.setColumnName("Numero");
            columnBinding3.setColumnClass(String.class);
            columnBinding3.setEditable(false);

            JTableBinding.ColumnBinding columnBinding4 = this.jTableBinding.addColumnBinding(ELProperty.create("${fecha_ingreso}"));

            columnBinding4.setColumnName("Fecha Registro");
            columnBinding4.setColumnClass(String.class);
            columnBinding4.setEditable(false);

            JTableBinding.ColumnBinding columnBinding5 = this.jTableBinding.addColumnBinding(ELProperty.create("${fecha_pago}"));

            columnBinding5.setColumnName("Fecha Pago");
            columnBinding5.setColumnClass(String.class);
            columnBinding5.setEditable(false);

            JTableBinding.ColumnBinding columnBinding6 = this.jTableBinding.addColumnBinding(ELProperty.create("${ruc_proveedor}"));

            columnBinding6.setColumnName("RUC");
            columnBinding6.setColumnClass(String.class);
            columnBinding6.setEditable(false);

            JTableBinding.ColumnBinding columnBinding7 = this.jTableBinding.addColumnBinding(ELProperty.create("${zona}"));

            columnBinding7.setColumnName("Zona");
            columnBinding7.setColumnClass(String.class);
            columnBinding7.setEditable(false);

            JTableBinding.ColumnBinding columnBinding8 = this.jTableBinding.addColumnBinding(ELProperty.create("${monto}"));

            columnBinding8.setColumnName("Monto");
            columnBinding8.setColumnClass(BigDecimal.class);
            columnBinding8.setEditable(false);

            this.bindingGroup.addBinding(this.jTableBinding);
            this.bindingGroup.bind();

        }

     private ParametrosConsultaTO getParametrosConsulta(){
         String zona = null;
        String anio = null;
        String mes = null;
        String ruc = null;
        String orden= null;
        if(this.jcboZona.getSelectedIndex()>=0)
             zona =((ZonaTO)this.jcboZona.getSelectedItem()).getId_zona();
        if(this.jcboAno.getSelectedIndex()>=0)
             anio = ((AnoTO)this.jcboAno.getSelectedItem()).getAno();
        if(this.jcboMes.getSelectedIndex()>=0)
             mes = ((MesTO)this.jcboMes.getSelectedItem()).getMes();
        if(this.jtfRuc.getText().trim().length()>0)
             ruc = this.jtfRuc.getText().trim();
        if(this.jtfNroOrden.getText().trim().length()>0)
             orden = this.jtfNroOrden.getText().trim();

            ParametrosConsultaTO parametros = new ParametrosConsultaTO();
            parametros.setAnio(anio);
            parametros.setMes(mes);
            parametros.setId_zona(zona);
            parametros.setRuc_proveedor(ruc);
            parametros.setNro_orden(orden);

             return parametros;
        }

     public void buscar(){
          try {
           params = getParametrosConsulta();
           int num_comprobantes_encontradas = GestionPedidosDelegate.getInstance().getNumeroDeComprobantes(params);
           panelPaginacion.setTotalResultados(num_comprobantes_encontradas);
        } catch (Exception e) {
            Utiles_MensajesDialogo.mensajeError(e.getMessage());
        }
     }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        cboBeanBindingZona1 = new administracion.BeanBinding.CboBeanBindingZona();
        cboBeanBindingAno1 = new administracion.BeanBinding.CboBeanBindingAno();
        cboBeanBindingMes1 = new administracion.BeanBinding.CboBeanBindingMes();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtComprobantes = new javax.swing.JTable();
        this.jtComprobantes.getTableHeader().setReorderingAllowed(false) ;
        jpOperativo = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jcboMes = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jcboZona = new javax.swing.JComboBox();
        jbBuscar = new javax.swing.JButton();
        jtfRazon = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jcboAno = new javax.swing.JComboBox();
        jtfRuc = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        jtfNroOrden = new javax.swing.JTextField();
        jbCancelar = new javax.swing.JButton();
        jbDetalles = new javax.swing.JButton();
        jbtImprimir = new javax.swing.JButton();
        jbModificar = new javax.swing.JButton();
        jbModificarDatos = new javax.swing.JButton();

        setIconifiable(true);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Comprobantes Encontrados", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12), java.awt.Color.blue)); // NOI18N
        jPanel1.setLayout(new java.awt.BorderLayout());
        jPanel1.add(panelPaginacion,java.awt.BorderLayout.NORTH);

        jtComprobantes.setAutoCreateRowSorter(true);
        jtComprobantes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nro Orden", "Comprobante", "Serie", "Numero", "Fecha Registro", "Fecha Pago", "RUC", "Zona"
            }
        ));
        jScrollPane1.setViewportView(jtComprobantes);

        jPanel1.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jpOperativo.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Busqueda Avanzada", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12), java.awt.Color.blue)); // NOI18N
        jpOperativo.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel1.setText("Año");
        jpOperativo.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(450, 50, -1, -1));

        jLabel2.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel2.setText("Mes");
        jpOperativo.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(580, 50, -1, -1));

        jcboMes.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingMes1, eLProperty, jcboMes);
        bindingGroup.addBinding(jComboBoxBinding);

        jcboMes.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcboMesKeyPressed(evt);
            }
        });
        jpOperativo.add(jcboMes, new org.netbeans.lib.awtextra.AbsoluteConstraints(610, 50, 76, -1));

        jLabel3.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel3.setText("SUCURSAL");
        jpOperativo.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 50, -1, -1));

        jcboZona.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingZona1, eLProperty, jcboZona);
        bindingGroup.addBinding(jComboBoxBinding);

        jcboZona.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcboZonaKeyPressed(evt);
            }
        });
        jpOperativo.add(jcboZona, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 50, 170, -1));

        jbBuscar.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jbBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/find.png"))); // NOI18N
        jbBuscar.setMnemonic('B');
        jbBuscar.setText("Buscar");
        jbBuscar.setToolTipText("Cancelar la Operacion");
        jbBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbBuscarActionPerformed(evt);
            }
        });
        jbBuscar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbBuscarKeyPressed(evt);
            }
        });
        jpOperativo.add(jbBuscar, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 70, -1, -1));

        jtfRazon.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jtfRazon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfRazonActionPerformed(evt);
            }
        });
        jtfRazon.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfRazonKeyPressed(evt);
            }
        });
        jpOperativo.add(jtfRazon, new org.netbeans.lib.awtextra.AbsoluteConstraints(291, 21, 390, -1));

        jLabel9.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/user.png"))); // NOI18N
        jLabel9.setText("PROVEEDOR");
        jpOperativo.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(189, 23, -1, -1));

        jLabel18.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel18.setText("RUC");
        jpOperativo.add(jLabel18, new org.netbeans.lib.awtextra.AbsoluteConstraints(16, 24, -1, -1));

        jcboAno.setFont(new java.awt.Font("Arial", 0, 12));

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingAno1, eLProperty, jcboAno);
        bindingGroup.addBinding(jComboBoxBinding);

        jcboAno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcboAnoActionPerformed(evt);
            }
        });
        jpOperativo.add(jcboAno, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 50, 78, -1));

        jtfRuc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfRucActionPerformed(evt);
            }
        });
        jpOperativo.add(jtfRuc, new org.netbeans.lib.awtextra.AbsoluteConstraints(58, 22, 113, -1));

        jLabel19.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel19.setText("Nº ORDEN");
        jpOperativo.add(jLabel19, new org.netbeans.lib.awtextra.AbsoluteConstraints(16, 49, -1, -1));

        jtfNroOrden.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfNroOrdenActionPerformed(evt);
            }
        });
        jpOperativo.add(jtfNroOrden, new org.netbeans.lib.awtextra.AbsoluteConstraints(83, 47, 90, -1));

        jbCancelar.setFont(new java.awt.Font("Arial", 1, 12));
        jbCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_cancel.png"))); // NOI18N
        jbCancelar.setMnemonic('C');
        jbCancelar.setText("CERRAR");
        jbCancelar.setToolTipText("Cancelar la Operacion");
        jbCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCancelarActionPerformed(evt);
            }
        });
        jbCancelar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbCancelarKeyPressed(evt);
            }
        });

        jbDetalles.setFont(new java.awt.Font("Arial", 1, 12));
        jbDetalles.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/view_detailed.png"))); // NOI18N
        jbDetalles.setMnemonic('D');
        jbDetalles.setText("VER DOCUMENTO");
        jbDetalles.setToolTipText("Cancelar la Operacion");
        jbDetalles.setEnabled(false);
        jbDetalles.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbDetallesActionPerformed(evt);
            }
        });

        jbtImprimir.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jbtImprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/document_print.png"))); // NOI18N
        jbtImprimir.setText("IMPRIMIR");
        jbtImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtImprimirActionPerformed(evt);
            }
        });
        jbtImprimir.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbtImprimirKeyPressed(evt);
            }
        });

        jbModificar.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jbModificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/edit.png"))); // NOI18N
        jbModificar.setText("CAMBIAR DOCUMENTO");
        jbModificar.setEnabled(false);
        jbModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbModificarActionPerformed(evt);
            }
        });

        jbModificarDatos.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jbModificarDatos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/edit.png"))); // NOI18N
        jbModificarDatos.setText("MODIFICAR");
        jbModificarDatos.setEnabled(false);
        jbModificarDatos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbModificarDatosActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 714, Short.MAX_VALUE)
                    .addComponent(jpOperativo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 714, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jbDetalles)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbModificar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbModificarDatos, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbtImprimir)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                        .addComponent(jbCancelar)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jpOperativo, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jbCancelar)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jbDetalles)
                        .addComponent(jbModificar)
                        .addComponent(jbModificarDatos)
                        .addComponent(jbtImprimir)))
                .addContainerGap())
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jcboMesKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcboMesKeyPressed

      /*  if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbBuscar.requestFocus();
        }*/
}//GEN-LAST:event_jcboMesKeyPressed

    private void jcboZonaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcboZonaKeyPressed
       
      /*  if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jcboAno.requestFocus();
        }*/
}//GEN-LAST:event_jcboZonaKeyPressed

    private void jbBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbBuscarActionPerformed
            buscar();
}//GEN-LAST:event_jbBuscarActionPerformed

    private void jbBuscarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbBuscarKeyPressed
        
      /*  if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbBuscar.doClick();
        }*/
}//GEN-LAST:event_jbBuscarKeyPressed

    private void jtfRazonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfRazonActionPerformed

        buscarRazonSocial();
        // this.jcboFormaPago.requestFocus();
}//GEN-LAST:event_jtfRazonActionPerformed

    private void jtfRazonKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfRazonKeyPressed
        if (this.jtfRuc.getText().trim().length() > 0)
            this.jtfRuc.setText("");
}//GEN-LAST:event_jtfRazonKeyPressed

    private void jtfRucActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfRucActionPerformed
        if (this.jtfRuc.getText().trim().length() < 1)
            this.jtfRazon.requestFocus();
        else
            buscarRazonSocial();
}//GEN-LAST:event_jtfRucActionPerformed

    private void jtfNroOrdenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfNroOrdenActionPerformed
      
    }//GEN-LAST:event_jtfNroOrdenActionPerformed

    private void jbCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCancelarActionPerformed
      
        this.dispose();
}//GEN-LAST:event_jbCancelarActionPerformed

    private void jbCancelarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbCancelarKeyPressed
       
}//GEN-LAST:event_jbCancelarKeyPressed

    private void jcboAnoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcboAnoActionPerformed
        llenarComboMes();
    }//GEN-LAST:event_jcboAnoActionPerformed

    private void jbDetallesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbDetallesActionPerformed
    
        int filaElegida = this.jtComprobantes.getSelectedRow();

        if (filaElegida < 0) {
            Utiles_MensajesDialogo.mensajeError("Debe elegir un Comprobante!");
            this.jtComprobantes.requestFocus();
            return;
        }

        try {
            ComprobantePagoTO cpto = (ComprobantePagoTO)this.comprobantes_encontradas.get(this.jtComprobantes.convertRowIndexToModel(filaElegida));
            byte[] archivo = GestionPedidosDelegate.getInstance().getComprobanteArchivo(cpto.getId_comprobante());
            //Reportes.verComprobante(cpto.getId_comprobante());
            if(archivo!=null){
                ByteArrayInputStream is = new ByteArrayInputStream(archivo);
                Utiles_PDF.verArchivo(is);
            }
            else
                Utiles_MensajesDialogo.mensajeAlerta("El comprobante no tiene asignado un archivo");

          //  Reportes.verImagen(is);
                //EPSPDFViewer visorpdf = new EPSPDFViewer(archivo);
                //visorpdf.mostrar();


          
        } catch (Exception e) {
            e.printStackTrace();
            Utiles_MensajesDialogo.mensajeError("No se pudo Cargar el archivo de comprobante\n" + e.getMessage());
        }
}//GEN-LAST:event_jbDetallesActionPerformed

    private void jbtImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtImprimirActionPerformed

        MiTablePrint pp = new MiTablePrint(this.jtComprobantes, "COMPROBANTES", "DETALLE DE COMPROBANTES");
        pp.showPrintPreview();
}//GEN-LAST:event_jbtImprimirActionPerformed

    private void jbtImprimirKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbtImprimirKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbtImprimir.doClick();
        }
}//GEN-LAST:event_jbtImprimirKeyPressed

    private void jbModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbModificarActionPerformed
          int filaElegida = this.jtComprobantes.getSelectedRow();

        if (filaElegida < 0) {
            Utiles_MensajesDialogo.mensajeError("Debe elegir un Comprobante!");
            this.jtComprobantes.requestFocus();
            return;
        }

        try {
            ComprobantePagoTO cpto = (ComprobantePagoTO)this.comprobantes_encontradas.get(this.jtComprobantes.convertRowIndexToModel(filaElegida));
              Frame frm = JOptionPane.getFrameForComponent((JInternalFrame)this);
             jdNuevoDocumento panel = new jdNuevoDocumento(frm,true);
             panel.setComprobante(cpto);
             panel.setTitle("Modificar Documento");
             panel.setLocationRelativeTo(null);
             panel.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
            Utiles_MensajesDialogo.mensajeError("No se pudo Cargar el archivo de comprobante\n" + e.getMessage());
        }
    }//GEN-LAST:event_jbModificarActionPerformed

    private void jbModificarDatosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbModificarDatosActionPerformed
         int filaElegida = this.jtComprobantes.getSelectedRow();

        if (filaElegida < 0) {
            Utiles_MensajesDialogo.mensajeError("Debe elegir un Comprobante!");
            this.jtComprobantes.requestFocus();
            return;
        }

        try {
            ComprobantePagoTO cpto = (ComprobantePagoTO)this.comprobantes_encontradas.get(this.jtComprobantes.convertRowIndexToModel(filaElegida));
              Frame frm = JOptionPane.getFrameForComponent((JInternalFrame)this);
             jdModificaComprobante panel = new jdModificaComprobante(frm,true,this);
             panel.setDatos(cpto);
             panel.setTitle("Modificar Datos");
             panel.setLocationRelativeTo(null);
             panel.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
            
        }
    }//GEN-LAST:event_jbModificarDatosActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private administracion.BeanBinding.CboBeanBindingAno cboBeanBindingAno1;
    private administracion.BeanBinding.CboBeanBindingMes cboBeanBindingMes1;
    private administracion.BeanBinding.CboBeanBindingZona cboBeanBindingZona1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbBuscar;
    private javax.swing.JButton jbCancelar;
    private javax.swing.JButton jbDetalles;
    private javax.swing.JButton jbModificar;
    private javax.swing.JButton jbModificarDatos;
    private javax.swing.JButton jbtImprimir;
    private javax.swing.JComboBox jcboAno;
    private javax.swing.JComboBox jcboMes;
    private javax.swing.JComboBox jcboZona;
    private javax.swing.JPanel jpOperativo;
    private javax.swing.JTable jtComprobantes;
    private javax.swing.JTextField jtfNroOrden;
    private javax.swing.JTextField jtfRazon;
    private javax.swing.JTextField jtfRuc;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    public void update(Observable o, Object arg) {
        buscarComprobantes();
    }

}
